package cn.org.timespace.ons.util.web;

import sun.misc.BASE64Decoder;

public class CodeingChange {
	private CodeingChange() {
	}

	public static String getBASE64(String s) {
		if (s == null)
			return null;
		return (new sun.misc.BASE64Encoder()).encode(s.getBytes());
	}

	public static String getFromBASE64(String s) {
		if (s == null)
			return null;
		BASE64Decoder decoder = new BASE64Decoder();
		try {
			byte[] b = decoder.decodeBuffer(s);
			return new String(b, "GBK");
		} catch (Exception e) {
			return null;
		}
	}

	public static String getGb2312FromBASE64(String s) {
		if (s == null)
			return null;
		BASE64Decoder decoder = new BASE64Decoder();
		try {
			byte[] b = decoder.decodeBuffer(s);
			return new String(b, "utf-8");
		} catch (Exception e) {
			return null;
		}
	}

}
